package com.sky.es.api;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sky.es.service.ProductAggsQueryEsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yangsk
 */
@RestController
@RequestMapping("es/aggs")
public class AggsQueryAPI {
    @Autowired
    private ProductAggsQueryEsService aggsQueryEsService;

    @ApiOperation(value = "bucket桶聚合分组查询", notes = "bucket桶聚合分组查询")
    @GetMapping("/bucket")
    public JSONArray getQueryAggsBucket(){
        return aggsQueryEsService.getQueryAggsBucket();
    }
    @ApiOperation(value = "metric聚合去重查询", notes = "metric聚合去重查询")
    @GetMapping("/matric")
    public void getQueryAggsMatric(){
        aggsQueryEsService.getQueryAggsMatric();
    }
    @ApiOperation(value = "metric-stats聚合统计查询", notes = "metric-stats聚合统计查询")
    @GetMapping("/stats")
    public JSONObject getQueryAggsMatricStats(){
       return aggsQueryEsService.getQueryAggsMatricStats();
    }

    @ApiOperation(value = "aggs聚合嵌套查询:统计不同品牌中的每个类型的商品数量")
    @GetMapping("/nest-aggs/one")
    public JSONArray getQueryByNestAggs(){
        return aggsQueryEsService.getQueryByNestAggs();
    }

    @ApiOperation(value = "aggs聚合嵌套查询:统计不同等级的商品的价格信息(平均价、最高、最低价)")
    @GetMapping("/nest-aggs/two")
    public JSONArray getQueryTwoByNestAggs(){
        return aggsQueryEsService.getQueryTwoByNestAggs();
    }
}
